<?php
	require_once("../classes/Announcement.php");
	require_once("../classes/EntryList.php");
	require_once("../classes/Database.php");
	
	session_start();
	
	$announcement = new Announcement();
	
	if(isset($_GET["enterprise"])){
		$ownerId = $_GET["enterprise"];
		$entry = new EntryList("entry");
		while($announcement->findByOwner($ownerId)){
			$entry->openEntry();
			$entry->addLinkTitle("announcement.php?ad=".$announcement->getId(), $announcement->getTitle());
			$entry->addEntry("Empresa:", $announcement->getOwnerName());
			$entry->addEntry("Categoria:", $announcement->getCategoryName());
			$entry->addEntry("Localiza&ccedil&atildeo:", $announcement->getLocationName());
			$entry->addEntry("Data:", $announcement->getSaveDate());
			$entry->closeEntry();
			$entry->addHtmlCode("</br></br>");
		}
	}else{
		$title = "%".$_POST["find"]."%";	
		$entry = new EntryList("entry");
		while($announcement->findByTitle($title)){
			$entry->openEntry();
			$entry->addLinkTitle("announcement.php?ad=".$announcement->getId(), $announcement->getTitle());
			$entry->addEntry("Empresa:", $announcement->getOwnerName());
			$entry->addEntry("Categoria:", $announcement->getCategoryName());
			$entry->addEntry("Localiza&ccedil&atildeo:", $announcement->getLocationName());
			$entry->addEntry("Data:", $announcement->getSaveDate());
			$entry->closeEntry();
			$entry->addHtmlCode("</br></br>");
		}
	}
	$_SESSION["entry"] = $entry;
	header("Location: ../findAnnouncement.php");
?>